package cn.chinaunicom.sdsi.frm.workflow.sample.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import cn.chinaunicom.sdsi.frm.workflow.common.WorkflowConstants;

/**
 * 普通流程控制层示例，业务模块开发不必继承ActTestServiceImpl
 * 
 * @author liyh
 *
 */
@Service("businessService")
public class BusinessServiceImpl extends ActTestServiceImpl {

	/**
	 * 普通环节流程推进方法
	 * 
	 * @param processInstanceId
	 *            流程实例ID
	 * @param taskId
	 *            任务ID
	 * @param taskDefinitionKey
	 *            任务定义KEY
	 * @param assignee
	 *            下环节任务处理人ID
	 * @param handleType
	 *            处理方式：1通过，2回退
	 * @param withdraw
	 *            当前推进操作是否可回退
	 * @param comment
	 *            用户处理意见
	 */
	@Override
	public void pushProcess(String processInstanceId, String taskId, String taskDefinitionKey, String assignee,
			int handleType, int withdraw, String comment) {

		/*
		 * 参数处理，handleType值为1时为通过，2时为回退 withdraw的值为1时为过程不可逆，0时为可撤回
		 */
		String handleTypeStr = "";
		if (handleType == 1) {
			handleTypeStr = WorkflowConstants.HANDLE_TYPE_PASS;
		} else if (handleType == 2) {
			handleTypeStr = WorkflowConstants.HANDLE_TYPE_BACK;
		}
		boolean isWithdraw = withdraw == 1 ? true : false;

		/*
		 * 首先处理业务逻辑，放在同一事务中
		 */
		Map<String, Object> vars = new HashMap<String, Object>();
		if (!"".equals(assignee)) {
			vars.put("assignee", assignee);
		}
		vars.put("handleType", handleTypeStr);
		workflowManager.pushProcess(taskId, processInstanceId, vars, comment, isWithdraw, taskDefinitionKey);

	}
}
